package com.itheima.mm.wx.controller;

import com.alibaba.fastjson.JSONObject;
import com.itheima.mm.context.WxBaseContext;
import com.itheima.mm.dto.WxCategoryDTO;
import com.itheima.mm.dto.WxMemberLoginDTO;
import com.itheima.mm.entity.Result;
import com.itheima.mm.pojo.WxMember;
import com.itheima.mm.utils.WxUtil;
import com.itheima.mm.vo.wx.WxCategoryVO;

import com.itheima.mm.wx.service.CategoryService;
import com.itheima.mm.wx.service.WxMemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description CategoryController
 * @Author Yc
 * @Date 2024-06-27
 */
@RestController
@Slf4j
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private WxMemberService wxMemberService;


    /**
     * 获取题库分类列表
     * @param wxCategoryDTO
     * @return
     */
    @GetMapping("/list.do")
    public Result<List<WxCategoryVO>> list(WxCategoryDTO wxCategoryDTO) {
        //String openId = "oDQVX48njUTb-4iQbel3hRpyoRIs";
        String openId = WxBaseContext.getCurrentId();
        WxMember wxMember = wxMemberService.findByOpenId(openId);

        log.info("获取题库分类列表");
        Integer memberId = wxMember.getId();
        Integer courseId = wxMember.getCourseId();
        Integer cityId = wxMember.getCityId();
        List<WxCategoryVO>WxCategoryVOList = categoryService.findCategory(wxCategoryDTO,memberId,courseId,cityId);
        return Result.success(WxCategoryVOList);
    }

    /**
     * 获取题库分类题目详情列表
     * @param map
     * @return
     */
    @PostMapping("/question/list.do")
    public Result<Map> questionList(@RequestBody Map<String,Object> map){
        log.info("获取题库分类题目详情列表");
        String openId = WxBaseContext.getCurrentId();
        map.put("openId",openId);
        WxMember wxMember = wxMemberService.findByOpenId(openId);
        log.info("openId:{}",openId);
        map.put("memberId",wxMember.getId());
        map.put("courseId",wxMember.getCourseId());
        map.put("cityId",wxMember.getCityId());
        //map.put("categoryID", 1);
        Map Resultmap = categoryService.findCategoryQuestion(map);
        return Result.success(Resultmap);
    }
}
